*****************************************************************************************************************************************************
* PROJECT: 		Exposure to the COVID-19 Stock Market Crash and its Effect on Household Expectations
* DATE: 		Nov 2020
* CONTENT: 		FIGURES
* AUTHORS: 		Tobin Hanspal, Johannes Wohlfart, Anni Weber
*****************************************************************************************************************************************************

		clear all
		set scheme lean2
		global pm = char(177)
		set more off
		gl date = c(current_date)
		graph set window fontface "cmr10"
		
		
* set cd as /Replication_files_HanspalWeberWohlfart2020/

*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~						
** FIGURE A14	
*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~	
			
use data/processed/data_1, clear 

* Scale USD variables	
	foreach x in  delofin_USD_tr02 delretir_USD_tr02  delfinwealth_USD_tr02   delhhnetinc_USD_tr02 ///
	delofin_USD_tr02alt delretir_USD_tr02alt  delfinwealth_USD_tr02alt	{
		replace `x' = `x'/1000
	}
	foreach x in ofinwealth_lvl retirewealth_lvl  finwealth_Jan20 hhinc_lvl hhnetinc_2019   {
		replace `x' = `x'/1000
	}
*
 replace del_retir_perc_tr02 = 0 if del_finwealth_perc_tr02!=. & del_ofin_perc_tr02!=. &del_retir_perc_tr02==.
 replace del_ofin_perc_tr02 = . if del_finwealth_perc_tr02==. & del_retir_perc_tr02==. &del_ofin_perc_tr02!=.
 replace del_ofin_perc_tr02 = . if del_finwealth_perc_tr02==. & del_retir_perc_tr02==.
 replace del_retir_perc_tr02 = . if del_finwealth_perc_tr02==. & del_ofin_perc_tr02==.
 replace del_ofin_perc_tr02 = 0 if del_finwealth_perc_tr02==. & del_ofin_perc_tr02==.

 gen first =  0
 replace first = 1 if svydate==date("06042020","DMY")
 replace first = 1 if svydate==date("07042020","DMY")
 replace first = 1 if svydate==date("08042020","DMY")
 gen second = 1-first
 keep if first==0
	
* top (percents)
	
  * change by netwealth	
	graph bar (mean) del_finwealth_perc_tr02 del_hhnetinc_perc_tr02 , ///
		over(netwealth_Jan20_grp, relabel(1 1 2 2 3 3 4 4 5 5)) b1title() ///
		bargap(0)  /// 
		ytitle("", size(medsmall)) ///
		yline(0, lcolor(gs8) lpattern(dash)) graphregion(color(white)) bgcolor(white) ///
		ylabel(-20(5)0, nogrid) ///
		legend(off) ///
		saving(Figures/temp4.gph, replace)
		
 * change by age		
	graph bar (mean)  del_finwealth_perc_tr02 del_hhnetinc_perc_tr02 , ///
		over(agecat, relabel(1 "18-24" 2 "25-34" 3 "35-44" 4 "45-54" 5 "55-64" 6 "65+") label(labsize(small))) b1title() ///
		 bargap(0)  /// 
		ytitle("") ///
		yline(0, lcolor(gs8) lpattern(dash)) graphregion(color(white)) bgcolor(white) ///
		ylabel(-20(5)0, nogrid)  ///
		legend(off) /// 
		saving(Figures/temp5.gph, replace)
		
		
 * change by hh net income		
	graph bar (mean) del_finwealth_perc_tr02 del_hhnetinc_perc_tr02 , ///
		over(hhnetinc_2019_grp) b1title() ///
		bargap(0)  /// 
		ytitle("") ///
		yline(0, lcolor(gs8) lpattern(dash)) graphregion(color(white)) bgcolor(white) ///
		ylabel(-20(5)0, nogrid) ///
		legend(off) ///
		saving(Figures/temp6.gph, replace)
			

* bottom (dollar amts)			
use data/processed/data_1, clear 
 gen first =  0
 replace first = 1 if svydate==date("06042020","DMY")
 replace first = 1 if svydate==date("07042020","DMY")
 replace first = 1 if svydate==date("08042020","DMY")
 gen second = 1-first
 keep if first==0
 collapse (mean) delfinwealth_USD_tr02alt delhhnetinc_USD_tr02alt_qtr, by(netwealth_Jan20_grp)
	drop if netwealth_Jan20_grp==.
	expand 2
	gen temp = (_n<=5)
	gen netwealth_Jan20_grp2 = netwealth_Jan20_grp-0.3 if temp==0
	
	replace delfinwealth_USD_tr02alt = delfinwealth_USD_tr02alt/1000
	replace delhhnetinc_USD_tr02alt_qtr = delhhnetinc_USD_tr02alt_qtr/1000	
	
	twoway (bar delfinwealth_USD_tr02alt netwealth_Jan20_grp2 , barw(0.3)) (bar delhhnetinc_USD_tr02alt_qtr netwealth_Jan20_grp , yaxis(2) barw(0.3)), ///
	ytitle("", size(medsmall)) ///
	ytitle("", size(medsmall) axis(2)) ///
	xtitle("Net wealth quintile") ///
		yline(0, lcolor(gs8) lpattern(dash)) graphregion(color(white)) bgcolor(white) ///
		ylabel(-100(20)0, nogrid axis(1) format(%9.0gc)) ///
		ylabel(-10(2)0, nogrid axis(2) format(%9.0gc)) ///
		yscale(r(-110(20)0) axis(1) ) ///
		yscale(r(-11(2)0)  axis(2) ) ///
		legend(off) ///
		saving(Figures/tempd4.gph, replace)
		
		
	
use data/processed/data_1, clear 
 gen first =  0
 replace first = 1 if svydate==date("06042020","DMY")
 replace first = 1 if svydate==date("07042020","DMY")
 replace first = 1 if svydate==date("08042020","DMY")
 gen second = 1-first
 keep if first==0
	collapse (mean) delfinwealth_USD_tr02alt delhhnetinc_USD_tr02alt_qtr, by(hhnetinc_2019_grp)
	drop if hhnetinc_2019_grp==.
	expand 2
	gen temp = (_n<=5)
	gen hhnetinc_2019_grp2 = hhnetinc_2019_grp-0.3 if temp==0
	
	replace delfinwealth_USD_tr02alt = delfinwealth_USD_tr02alt/1000
	replace delhhnetinc_USD_tr02alt_qtr = delhhnetinc_USD_tr02alt_qtr/1000	
	
	twoway (bar delfinwealth_USD_tr02alt hhnetinc_2019_grp2 , barw(0.3)) (bar delhhnetinc_USD_tr02alt_qtr hhnetinc_2019_grp , yaxis(2) barw(0.3)), ///
	ytitle("", size(medsmall)) ///
	ytitle("", size(medsmall) axis(2)) ///
	xtitle("Net income quintile") ///
		yline(0, lcolor(gs8) lpattern(dash)) graphregion(color(white)) bgcolor(white) ///
		ylabel(-100(20)0, nogrid axis(1) format(%9.0gc)) ///
		ylabel(-10(2)0, nogrid axis(2) format(%9.0gc)) ///
		legend(off) ///
		saving(Figures/tempd6.gph, replace)
		
	
use data/processed/data_1, clear 
 gen first =  0
 replace first = 1 if svydate==date("06042020","DMY")
 replace first = 1 if svydate==date("07042020","DMY")
 replace first = 1 if svydate==date("08042020","DMY")
 gen second = 1-first
 keep if first==0
	collapse (mean) delfinwealth_USD_tr02alt delhhnetinc_USD_tr02alt_qtr, by(agecat)
	drop if agecat==.
	expand 2
	gen temp = (_n<=5)
	gen agecat2 = agecat-0.3 if temp==0
	
	replace delfinwealth_USD_tr02alt = delfinwealth_USD_tr02alt/1000
	replace delhhnetinc_USD_tr02alt_qtr = delhhnetinc_USD_tr02alt_qtr/1000	
	
	twoway (bar delfinwealth_USD_tr02alt agecat2 , barw(0.3)) (bar delhhnetinc_USD_tr02alt_qtr agecat , yaxis(2) barw(0.3)), ///
	ytitle("", size(medsmall)) ///
	ytitle("", size(medsmall) axis(2)) ///
	xtitle("Age group") ///
	xlabel(1 "18-24" 2 "25-34" 3 "35-44" 4 "45-54" 5 "55-64" 6 "65+", labsize(small)) ///
		yline(0, lcolor(gs8) lpattern(dash)) graphregion(color(white)) bgcolor(white) ///
		ylabel(-100(20)0, nogrid axis(1) format(%9.0gc)) ///
		ylabel(-10(2)0, nogrid axis(2) format(%9.0gc)) ///
		legend(size(small) pos(6) ring(1) cols(6) ///
		label(1 "Total financial wealth") label(2 "Household net income")) ///
		saving(Figures/tempd5.gph, replace)

	graph combine 	Figures/temp4.gph ///
					Figures/temp6.gph ///
					Figures/temp5.gph ///
					, cols(3) rows(1) ysize(1) xsize(3) ///
					l1title("Percentage change (%)", size(small)) ///
					r1title(" " , size(small)) ///
					saving(Figures/temptop2.gph, replace) imargin(+3 +3 +3 +3 )	

	grc1leg2 		Figures/tempd4.gph ///
					Figures/tempd6.gph ///
					Figures/tempd5.gph,  ///
					l1title("Change financial wealth (left axis $1000)", size(small)) ///
					r1title("Change net income (right axis $1000)" , size(small)) ///
					cols(3) rows(1) ysize(1) xsize(3) lsize(small) iscale(.7) ///
					legendfrom(Figures/tempd5.gph) ///
					saving(Figures/tempbot2.gph, replace) 					
	
	graph combine  	Figures/temptop2.gph ///
					Figures/tempbot2.gph, cols(1) rows(2) ysize(2) xsize(3)  
			
	graph export Figures/FigureA14.pdf, as(pdf)  fontface("cmr10") replace								
	graph export Figures/FigureA14.png,  width(1600) replace		
	
	
forvalues x = 4/6 {
		capture erase Figures/temp`x'.gph
		capture erase Figures/tempd`x'.gph
}		
		capture erase Figures/temptop2.gph
		capture erase Figures/tempbot2.gph
